<template>
  <div>
    <el-drawer
      :title="state.FromTitle"
      v-model="drawer"
      direction="rtl"
      :before-close="handleClose"
      custom-class="demo-drawer"
      destroy-on-close
    >
      <div class="demo-drawer__content">
        <el-form ref="form" :model="state.form" label-width="80px">
          <el-form-item label="菜单名称">
            <el-input
              v-model="state.form.name"
              placeholder="请输入菜单名称"
            ></el-input>
          </el-form-item>
          <el-form-item label="菜单路径">
            <el-input
              v-model="state.form.path"
              placeholder="请输入菜单路径"
            ></el-input>
          </el-form-item>
          <el-form-item label="上级菜单">
            <el-select v-model="state.form.submenu" placeholder="">
              <el-option
                v-for="(item, index) in state.submenuList"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="描述">
            <el-input
              v-model="state.form.describe"
              placeholder="请输入描述"
            ></el-input>
          </el-form-item>
          <el-form-item label="前端图标">
            <el-input
              v-model="state.form.icon"
              placeholder="请输入前端图标"
            ></el-input>
          </el-form-item>
          <el-form-item label="是否显示">
            <el-radio-group v-model="state.form.radio">
              <el-radio label="是" value="1"></el-radio>
              <el-radio label="否" value="2"></el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="排序">
            <el-input
              v-model="state.form.sorting"
              placeholder="请输入排序"
            ></el-input>
          </el-form-item>
        </el-form>
        <div class="demo-drawer__footer">
          <el-button @click="cancelForm">取 消</el-button>
          <el-button type="primary" @click="onSubmit" :loading="loading">{{
            loading ? "提交中 ..." : "确 定"
          }}</el-button>
        </div>
      </div>
    </el-drawer>
  </div>
</template>
<script lang="ts">
import { defineComponent, reactive, ref } from "vue";
import { FETCH_URLS } from "@/config";
import request from "@/utils/request";
export default defineComponent({
  name: "addMenu",
  setup() {
    const drawer = ref<boolean>(false);
    const loading = ref<boolean>(false);
    const state = reactive<any>({
      FromTitle: "新增菜单",
      form: {
        name: "",
        path: "",
        submenu: "",
        describe: "",
        icon: "",
        radio: "",
        sorting: "",
      },
      submenuList: [],
    });

    const fetchSubMenu = async () => {
      const params = {
        id: -1,
      };
      const res = await request.get(FETCH_URLS.SYSTEM_EDITMENUINFO, { params });
      state.submenuList = res.data.data.parentMenuList;
    };
    const initShow = () => {
      drawer.value = true;
      fetchSubMenu();
    };
    const handleClose = () => {
      drawer.value = false;
    };
    const onSubmit = () => {
      console.log("submit!");
    };
    const cancelForm = () => {
      console.log("取消!");
    };
    return {
      drawer,
      state,
      handleClose,
      onSubmit,
      fetchSubMenu,
      initShow,
      loading,
      cancelForm,
    };
  },
});
</script>
<style lang="scss" scoped></style>
